package com.goktech.olala.core.service.impl;

import com.goktech.olala.core.resp.RespArticleVo;
import com.goktech.olala.core.service.IArticleService;
import com.goktech.olala.server.dao.goods.ArticleMapper;
import com.goktech.olala.server.pojo.goods.Article;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author sanming
 * @Classname ArticleServiceImp
 * @Description TODO
 * @Date 2020/11/29
 */
@Service
public class ArticleServiceImp implements IArticleService {

    @Autowired
    ArticleMapper articleMapper;



    @Override
    public List<Article> selectAll() {
        List<Article> articles = articleMapper.selectAll();
        return articles;
    }

    @Override
    public RespArticleVo queryArticleById(Integer articleId) {
        if(articleId == null){
            return null;
        }
        RespArticleVo respArticleVo = new RespArticleVo();
        Article indexNews = articleMapper.selectByPrimaryKey(articleId);
        BeanUtils.copyProperties(indexNews, respArticleVo);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(indexNews.getCommentBeginTime() != null){
            respArticleVo.setCommentBeginTime(sdf.format(indexNews.getCommentBeginTime()));
        }
        if(indexNews.getCommentEndTime() != null){
            respArticleVo.setCommentEndTime(sdf.format(indexNews.getCommentEndTime()));
        }
        respArticleVo.setCreateTime(sdf.format(indexNews.getCreateTime()));
        respArticleVo.setUpdateTime(sdf.format(indexNews.getUpdateTime()));
        return respArticleVo;
    }


}
